//
//  MinePartyVerfityController.m
//  village_ios
//
//  Created by mac on 2019/8/11.
//  Copyright © 2019 com.sw.village. All rights reserved.
//
/**
 a. 标题——请输入党员信息
 b. 所在支部——选择，下拉菜单（包括北亭村党委、第一党支部、第二党支部、第三党支部、第四党支部、来穗人员流动支部）
 c. 党员身份——选择，下拉菜单（包括正式党员、预备党员、发展对象、入党积极分子）
 d. 党内职务——直接填写
 */

#import "MinePartyVerfityController.h"
#import "UIAlertController+Blocks.h"
@interface MinePartyVerfityController()
@property (weak, nonatomic) IBOutlet UITextField *branchTextField;
@property (weak, nonatomic) IBOutlet UITextField *partyMemberTextField;
@property (weak, nonatomic) IBOutlet UITextField *partyJobTextField;
@property (strong, nonatomic) NSMutableDictionary *dictTemp;
@end

@implementation MinePartyVerfityController

- (void)viewDidLoad {
    [super viewDidLoad];
 }

- (IBAction)toBranch:(id)sender {
    
    __block NSArray *branchs = @[@"北亭村党委",@"第一党支部",@"第二党支部",@"第三党支部",@"第四党支部",@"来穗人员流动支部"];
    __weak typeof(self) weakSelf = self;

    [UIAlertController showAlertInViewController:self withTitle:@"选择支部" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:branchs tapBlock:^(UIAlertController * _Nonnull controller, UIAlertAction * _Nonnull action, NSInteger buttonIndex) {
        
        NSString *branch = branchs[buttonIndex-2];
        weakSelf.branchTextField.text = branch;
    }];
}

- (IBAction)toPartyMember:(id)sender {
    
    __block NSArray *partyMembers = @[@"正式党员",@"预备党员",@"发展对象",@"入党积极分子"];
    __weak typeof(self) weakSelf = self;

    [UIAlertController showAlertInViewController:self withTitle:@"选择党员身份" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:partyMembers tapBlock:^(UIAlertController * _Nonnull controller, UIAlertAction * _Nonnull action, NSInteger buttonIndex) {
        
        NSString *partyMember = partyMembers[buttonIndex-2];
        weakSelf.partyMemberTextField.text = partyMember;
        
    }];
}

- (IBAction)toDone:(id)sender {
    
    [UIAlertController showAlertInViewController:self withTitle:@"是否确认" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil tapBlock:^(UIAlertController * _Nonnull controller, UIAlertAction * _Nonnull action, NSInteger buttonIndex) {
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        if (self.branchTextField.text) {
            [params addEntriesFromDictionary:@{@"branch":self.branchTextField.text}];
        }
        if (self.partyMemberTextField.text) {
            [params addEntriesFromDictionary:@{@"partyMember":self.partyMemberTextField.text}];
        }
        if (self.partyJobTextField.text) {
            [params addEntriesFromDictionary:@{@"partyJob":self.partyJobTextField.text}];
        }
        [SYProgressHUD show];
        [APIManager requestWithUrlString:@"api/user/verify" params:params method:@"POST" success:^(id response) {
            
            [SYProgressHUD showSuccessText:@"提交成功"];
            [self.navigationController popViewControllerAnimated:YES];
        } failure:^(NSError *error) {
            [SYProgressHUD showInfoText:@"提交失败"];

        }];
        
    }];
    
}
@end
